package com.my.chapter6;

import java.lang.reflect.Array;
import java.util.Arrays;

public class practice8 {
    public static Connection[] cons = new Connection[5];
    static{
        System.out.println("初始化Connection对象");
        for(int i=0;i<5;i++){
            cons[i] = Connection.makeConnection();
        }
    }

    public static Connection getConnection(){
        int length = cons.length;
        if(length>0){
            Connection con = cons[--length];
            cons  = Arrays.copyOf(cons,length);
            return con;
        }else{
            return null;
        }
    }


    public static void main(String[] args) {
        for(int i=1;i<7;i++){
            Connection con = getConnection();
            System.out.println(i+": "+con);
        }
    }
}

class Connection{

    private static Connection connection=new Connection();

    private Connection(){

    }

    public static Connection makeConnection(){
        return connection;
    }
}
